package com.example.TodayNews.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.TodayNews.R;
import com.example.TodayNews.model.News;

import java.util.List;

/**
 * Created by Administrator on 2015/6/16.
 */
public class ListItemAdapter extends BaseAdapter {
    private List<News> newsList;
    private Context context;
    private LayoutInflater inflater;

    public ListItemAdapter(Context context, List<News> newsList) {
        this.context = context;
        this.newsList = newsList;
        if (context!=null)
        {
            inflater=LayoutInflater.from(context);
        }
    }

    @Override
    public int getCount() {
        int ret=0;
        if (newsList!=null)
        {
            ret=newsList.size();
        }
        return ret;
    }

    @Override
    public int getViewTypeCount() {

        return 5;
    }

    @Override
    public int getItemViewType(int position) {
        int ret=1;
        News news=newsList.get(position);
        String picOne=news.getPicOne();
        String picOneBig=news.getPicOneBig();
        String picOneAdvertise=news.getPicOneAdvertise();
        String picOneSubject=news.getPicOneSubject();
        String picThr=news.getPicThr();
        if ("".equals(picOne))
        {
           ret=1;
        }else if (picOne.length()>0&&"".equals(picOneBig))
        {
            ret=2;
        }else if (picOne.length()>0&&"".equals(picOneAdvertise))
        {
            ret=3;
        }else if (picOne.length()>0&&"".equals(picOneSubject))
        {
            ret=4;
        }else if (picOne.length()>0&&"".equals(picThr))
        {
            ret=5;
        }
        return ret;
    }

    @Override
    public Object getItem(int position) {
        Object ret=null;
        if (newsList!=null)
        {
            ret=newsList.get(position);
        }
        return ret;
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View ret=null;
        News news=newsList.get(position);
        String picOne=news.getPicOne();
        String picOneBig=news.getPicOneBig();
        String picOneAdvertise=news.getPicOneAdvertise();
        String picOneSubject=news.getPicOneSubject();
        String picThr=news.getPicThr();
        if ("".equals(picOne))
        {
            if (convertView!=null)
            {
                ret=convertView;
            }else {
                ret=inflater.inflate(R.layout.news_item_one_pic,parent,false);
            }
            OnePicViewHolder onePicViewHolder= (OnePicViewHolder) ret.getTag();
            if (onePicViewHolder==null)
            {
                onePicViewHolder=new OnePicViewHolder();
                onePicViewHolder.tv_title= (TextView) ret.findViewById(R.id.news_item_one_pic_title);
                onePicViewHolder.tv_content= (TextView) ret.findViewById(R.id.news_item_one_pic_content);
                onePicViewHolder.image_one= (ImageView) ret.findViewById(R.id.news_item_one_pic_image);
                onePicViewHolder.tv_fllow= (TextView) ret.findViewById(R.id.news_item_one_pic_fllow);
                ret.setTag(onePicViewHolder);
            }

        }else if (picOne.length()>0&&"".equals(picOneBig))
        {

        }else if (picOne.length()>0&&"".equals(picOneAdvertise))
        {

        }else if (picOne.length()>0&&"".equals(picOneSubject))
        {

        }else if (picOne.length()>0&&"".equals(picThr))
        {

        }
        return null;
    }
    //一个图片
    public class OnePicViewHolder{
        //标题
        public TextView tv_title;
        //内容
        public TextView tv_content;
        //跟帖
        public TextView tv_fllow;
        //一个图片
        public ImageView image_one;

    }
    //一个图片带有专题
    public class OneSubjectPicViewHolder extends OnePicViewHolder{
        //专题
        public TextView tv_subject;
    }
    //一个大图
    public  class OneBigPicViewHolder extends OnePicViewHolder{
        //独家
        public TextView tv_unique;
    }
    //广告一个大图
    public  class AdvertiseViewHolder extends OnePicViewHolder
    {
        //推广
        public TextView tv_recommend;
    }
    //带有三个图片
    public class ThreePicViewHolder extends OnePicViewHolder
    {
        //第二个图片
        public ImageView image_two;
        //第三个图片
        public ImageView image_three;
    }

}
